<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改密码--layui后台管理模板</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../js/layui/css/layui.css"
	media="all" />
<script src="../../js/layui/layui.js"></script>
	<link rel="stylesheet" href="../../css/user.css" media="all" />
	<script type="text/javascript" src="../../js/nav.js"></script>
	<script type="text/javascript" src="../../js/leftNav.js"></script>
	<script type="text/javascript" src="../../js/index.js"></script>
</head>
<body class="childrenBody">
	<form class="layui-form changePwd" id="Form" lay-filter="form">
	<input	type="hidden" name="id" id="id" value="" class="layui-input">
		<div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		    	<input type="text" value="" name="name" disabled class="layui-input layui-disabled">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">旧密码</label>
		    <div class="layui-input-block">
		    	<input type="password" value="" id="oldPwd" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">新密码</label>
		    <div class="layui-input-block">
		    	<input type="password" value=""  placeholder="请输入新密码" lay-verify="required|pass" id="newPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">确认密码</label>
		    <div class="layui-input-block">
		    	<input type="password" name="newPwd" value="" placeholder="请确认密码" id="pwd" lay-verify="required|confirmPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <div class="layui-input-block">
		    	<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
		    
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript">
		layui
				.use(
						[ 'upload', 'layer', 'form' ],
						function() {
							var upload = layui.upload, $ = layui.$, form = layui.form, layer = layui.layer;
							var d=null;
							$(function() {
								 $.post('../../../AdminServlet?reqName=getUser',
												function(res){
									 d=res.data[0];
									 form.val("form",{
											
											"name":d.uName,
											
											"id":d.uId
										});
								}, "json");
								
							})
							$("#oldPwd").blur(function(e){
								if(d.uPwd==$("#oldPwd").val()){
									layer.msg("密码正确", {icon: 6});
								}else{
									layer.msg("密码错误", {icon: 5});
								}
							})
							$("#newPwd").blur(function(e){
								if($("#oldPwd").val()!=$("#newPwd").val()){
									if(/^[\S]{6,12}$/.test($("#newPwd").val())){
										layer.msg("密码格式正确", {icon: 6});
									}
									else{
										layer.msg("密码必须6到12位", {icon: 5});
									}
								}else{
									
										layer.msg("新密码不可以与旧密码相同", {icon: 5});
									
								}
								
							})
							$("#pwd").blur(function(e){
								if($("#newPwd").val()==$("#pwd").val()){
									layer.msg("两次输入密码相同", {icon: 6});
								}else{
									layer.msg("两次输入密码不同", {icon: 5});
								}
							})
							
							form.on('submit(changePwd)',
											function(data) {
												$.post('../../../AdminServlet?reqName=updatePwd',
																$("#Form").serialize(),
																function(res) {
																	if (res) {
																		var index = top.layer
																				.msg(
																						'数据提交中，请稍候',
																						{
																							icon : 16,
																							time : false,
																							shade : 0.8
																						});
																		setTimeout(
																				function() {
																					top.layer
																							.close(index);
																					top.layer
																							.msg("密码修改成功！");
																					//location.reload();
																					history.back();
																					// window.location.assign("http://localhost:8080/Nature/admin/login.html");
																					//location.href='../../index.html'
																					//location.href='http://localhost:8080/Nature/admin/login.html';
																					},
																				1000);
																	} else {
																		var index = top.layer
																				.msg(
																						'数据提交中，请稍候',
																						{
																							icon : 16,
																							time : false,
																							shade : 0.8
																						});
																		setTimeout(
																				function() {
																					top.layer
																							.close(index);
																					top.layer
																							.msg("密码修改失败！");

																				},
																				1000);
																	}
																}, "text")
												return false;
											})
						});
	</script>
</body>
</html>